package cn.kgc.tangcco.controller;

import cn.kgc.tangcco.model.InMessage;
import cn.kgc.tangcco.model.OutMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;


@Controller
public class GameInfoController {

	@Autowired
	private SimpMessagingTemplate messagingTemplate;


	@MessageMapping("/chat")
	@SendTo("/topic/game_chat")
	public OutMessage gameInfo(InMessage message){
		return new OutMessage(message.getContent());
	}

	@MessageMapping("/broadcast")
	public void broadcast(InMessage message){
		this.messagingTemplate.convertAndSend("/topic/game_chat",new OutMessage(message.getContent()));
	}

	@MessageMapping("/p2p")
	public void p2p(InMessage message){
		this.messagingTemplate.convertAndSendToUser("","/topic/game_chat",new OutMessage(message.getContent()));
	}
}



